<template>
  <zeda-dialog
    title="设备信息包详情"
    v-model="visible"
    width="1000px"
    append-to-body
    :before-close="handleClose"
  >
    <Title slot="green">
      <desc-base-info
        :data="info"
        :colnum-info="baseInfo"
        align="right"
        :no-line-height="true"
        label-width="120px"
        class="base-info"
      >
      </desc-base-info>
    </Title>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submit" size="small">确 定</el-button>
      <!-- <el-button @click="handleClose" size="small">取 消</el-button> -->
    </div>
  </zeda-dialog>
</template>

<script>
import { getPlugDetails } from "@/api/iot/maintenance.js";
export default {
  components: {},
  props: {
    visible: { type: Boolean, default: false },
    id: { type: [String, Number], default: 0 },
  },
  data() {
    return {
      info: {},
      tableData: [],
    };
  },
  watch: {
    visible(value) {
      if (value) {
        this.getDetails();
      }
    },
  },
  created() {},
  computed: {
    baseInfo({ info }) {
      let that = this;
      let arr = [];
      arr = that.tableData;
      return arr;
    },
  },
  methods: {
    submit() {
      this.handleClose();
    },
    handleClose() {
      // this.resetForm("form");
      this.$emit("update:visible");
    },
    getDetails() {
      this.tableData = [];
      getPlugDetails(this.id)
        .then((res) => {
          if (res.code === 700) {
            this.$message.warning(res.msg);
            return false;
          }
          // console.log(res, "details");
          let details = res?.data ?? {};
          if (Object.keys(details).length > 0) {
            for (var key in details) {
              let obj = {
                label: key,
                value: details[key],
                colNum: key == "原数据" ? 1 : 2,
              };
              if (obj.value) {
                this.tableData.push(obj);
              }
            }
          }
          // console.log(this.tableData, "data");
        })
        .catch((err) => {
          // this.$message.error("系统错误,请联系管理员!200201");
        });
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
